import Api from "@/api/thirdGames/games";
import i18n from "@/lang/index";
const modalConfig = {
  pageName: 'sys:user',
  dialog: {
    title: i18n.global.t('title.4'),
    width: 800,
    appendToBody: true,
    draggable: true,
    labelWidth: "auto",
  },
  formAction: (data) => {
    console.log('edit', data)
    return new Promise((resolve, reject) => {
      Api.put(data).then((s) => {
        console.log(s)
        resolve(s)
      }).catch((e) => {
        reject(e)
      })
    })
  },
  formItems: [
    {
      type: "input",
      label: "ID",
      prop: "id",
      attrs: {
        disabled: true
      },
      hidden: true,
    },
    {
      type: "custom",
      label: i18n.global.t("form.8"),
      prop: "game_provider_id",
      attrs: {
        placeholder: i18n.global.t("hint.19"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "input",
      label: i18n.global.t("form.9"),
      prop: "name",
      attrs: {
        placeholder: i18n.global.t("hint.20"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "gameUpload",
      label: i18n.global.t("form.10"),
      prop: "thumbnail",
      attrs: {
        placeholder: i18n.global.t("hint.21"),
      },
    },

    {
      type: "input",
      label: "slug",
      prop: "slug",
      attrs: {
        placeholder: i18n.global.t("hint.22"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "input",
      label: "code",
      prop: "code",
      attrs: {
        placeholder: i18n.global.t("hint.23"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "custom",
      label: i18n.global.t("form.11"),
      prop: "categories",
      attrs: {
        multiple: false,
      },
      col: {
        span: 12
      }
    },
    // {
    //   type: "input",
    //   label: "meta",
    //   prop: "meta",
    //   attrs: {
    //     placeholder: i18n.global.t("key与value以:分割，同对象以,分割，多对象以;分割(实例：pg_id: 123456, foo: bar;pg_id: 321, foo: bar)"),
    //     type: "textarea",
    //     autosize: true
    //   }
    // },
    {
      type: "custom",
      label: "meta",
      prop: "meta",
      col: {
        span: 24,
      },
    },
    {
      type: "input",
      label: i18n.global.t("form.12"),
      prop: "sort",
      attrs: {
        placeholder: i18n.global.t("hint.24"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "input",
      label: i18n.global.t("form.39"),
      prop: "help-text",
      attrs: {
        placeholder: i18n.global.t("hint.64"),
      },
      col: {
        span: 12
      }
    },
    {
      type: "radio",
      label: i18n.global.t("form.13"),
      prop: "popular",
      options: [
        { label: i18n.global.t("status.2"), value: 0 },
        { label: i18n.global.t("status.1"), value: 1 },
      ],
      initialValue: 0,
      col: {
        span: 12
      }
    },
    {
      type: "select",
      label: i18n.global.t("form.38"),
      prop: "status",
      options: [
        { label: i18n.global.t("status.21"), value: 0 },
        { label: i18n.global.t("status.22"), value: 1 },
        { label: i18n.global.t("status.23"), value: 2 },
        { label: i18n.global.t("status.24"), value: 3 },
      ],
      initialValue: 0,
      col: {
        span: 12
      }
    }
  ],
  formRules: {
    game_provider_id: [{ required: true, message: i18n.global.t("hint.19"), trigger: "blur" }],
    name: [{ required: true, message: i18n.global.t("hint.20"), trigger: "blur" }],
    slug: [{ required: true, message: i18n.global.t("hint.22"), trigger: "blur" }],
    code: [{ required: true, message: i18n.global.t("hint.23"), trigger: "blur" }],
    category_id: [{ required: true, message: i18n.global.t("hint.25"), trigger: "blur" }],
    sort: [{ required: true, message: i18n.global.t("hint.24"), trigger: "blur" }],
    popular: [{ required: true, message: i18n.global.t("hint.26"), trigger: "blur" }],
    // thumbnail: [{ required: true, message: i18n.global.t("hint.21"), trigger: "blur" }],
    meta: [
      { required: true, message: i18n.global.t("hint.129"), trigger: "blur" },
      {
      validator: (rule, value, callback) => {
        if (!value[0].key || !value[0].value) {
          callback(new Error(i18n.global.t('hint.129')));
          return;
        }
        
        if (value[0].key === 'interval' && !value[0].value) {
          callback(new Error(i18n.global.t('hint.130')));
          return;
        }

        for (let i = 0; i < value.length; i++) {
          if (!Boolean(value[i].key && value[i].key.trim()) || !Boolean(value[i].value && value[i].value.trim())) {
            callback(new Error(i18n.global.t('hint.131',{value:i + 1})));
            return;
          }
        }
        
        callback();
      },
      trigger: ['change','blur']
    }],
  },
}

export default modalConfig
